import type { CartItem, createCartItem } from "@/types/cart"
import { http } from "@/utils/https"
/**
 *
 * @param data 请求体参数
 * @returns
 */
// 创建购物车
export const postMemberCartAPI = (data: createCartItem) => {
  return http({
    method: 'POST',
    url: '/cart/create',
    data
  })
}

// 获取购物车列表
export const getMemberCartAPI = (id: string) => {
  const res = http<CartItem[]>({
    method: 'GET',
    url: `/cart/userId?userId=${id}`
  })
  return res
}

/**
 *
 * @param data 请求体参数 ids为sku的id
 * @returns
 */
// 删除购物车数据
export const deleteMemberCartAPI = (cartId: string) => {
  return http({
    method: 'DELETE', url: `/cart/remove/id?id=${cartId}`
  })
}

// 修改购物车数量
/**
 *
 * @param skuId SKUID
 * @param data selected 选中状态 count 商品数量
 * @returns
 */
export const putMemberCartBySkuAPI = (skuId: string, data: { selected?: boolean, count?: number }) => {
  return http({
    method: 'POST',
    url: `/cart/update?id=${skuId}`,
    data
  })
}
/**
 *
 * @param data 请求体数据 selected选中状态
 * @returns
 */
export const putMemberCartSelectedAPI = (id: string, data: { selection: boolean }) => {
  console.log('请求了')
  return http({
    method: 'POST',
    url: `/cart/change_select?userId=${id}`,
    data
  })
}


/**
 *
 * 在创建订单成功之后,删除被选中的购物车
 */
export const deleteSelected = (id: string) => {
  return http({
    method: 'DELETE',
    url: `/cart/delete?id=${id}`
  })
}
